package com.next

import grails.gorm.transactions.Transactional

/**
 * @Author 班旭娟
 * @CreatedDate 2017-5-8
 */
@Transactional
class ComponentService
{

    static scope = "singleton"

    def evaluate(Component component, Object object)
    {
        def shell = new GroovyShell()
        def closure
        def result

        try
        {
            closure = shell.evaluate(component?.script)
            if (!object)
            {
                result = closure
            } else
            {
                result = closure(object)
            }
        }
        catch (Exception e)
        {
            println e
            result = e
        }

        return result
    }

    /** @Description 提出WorkflowInstanceNotificationService里面的公共方法
      * @Params string,WorkflowInstance
      * @Return string
      * @Author Nagelan
      * @DateTime 2018/10/9 0009 17:30
      */
    String evaluate(String tellphone, WorkflowInstance workflowInstance)
    {
        def shell = new GroovyShell()
        def closure = shell.evaluate(tellphone)
        return closure(workflowInstance)
    }
}
